{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Shuffle the Array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: shuffle"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #重新排列数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个数组 <code>nums</code> ，数组中有 <code>2n</code> 个元素，按 <code>[x<sub>1</sub>,x<sub>2</sub>,...,x<sub>n</sub>,y<sub>1</sub>,y<sub>2</sub>,...,y<sub>n</sub>]</code> 的格式排列。</p>\n",
    "\n",
    "<p>请你将数组按 <code>[x<sub>1</sub>,y<sub>1</sub>,x<sub>2</sub>,y<sub>2</sub>,...,x<sub>n</sub>,y<sub>n</sub>]</code> 格式重新排列，返回重排后的数组。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [2,5,1,3,4,7], n = 3\n",
    "<strong>输出：</strong>[2,3,5,4,1,7] \n",
    "<strong>解释：</strong>由于 x<sub>1</sub>=2, x<sub>2</sub>=5, x<sub>3</sub>=1, y<sub>1</sub>=3, y<sub>2</sub>=4, y<sub>3</sub>=7 ，所以答案为 [2,3,5,4,1,7]\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [1,2,3,4,4,3,2,1], n = 4\n",
    "<strong>输出：</strong>[1,4,2,3,3,2,4,1]\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [1,1,2,2], n = 2\n",
    "<strong>输出：</strong>[1,2,1,2]\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= n &lt;= 500</code></li>\n",
    "\t<li><code>nums.length == 2n</code></li>\n",
    "\t<li><code>1 &lt;= nums[i] &lt;= 10^3</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [shuffle-the-array](https://leetcode.cn/problems/shuffle-the-array/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [shuffle-the-array](https://leetcode.cn/problems/shuffle-the-array/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[2,5,1,3,4,7]\\n3', '[1,2,3,4,4,3,2,1]\\n4', '[1,1,2,2]\\n2']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSecretWord(self, words: List[str], master: 'Master') -> None:\n",
    "        def func(w1, w2):\n",
    "            return sum(l1 == l2 for l1, l2 in zip(w1, w2))\n",
    "        while True:\n",
    "            shuffle(words)\n",
    "            g = master.guess(words[0])\n",
    "            if   g == 6: return\n",
    "            elif g == 0: words = [w for w in words[1:] if func(w, words[0]) == 0]\n",
    "            else       : words = [w for w in words[1:] if func(w, words[0]) >= g]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSecretWord(self, words: List[str], master: 'Master') -> None:\n",
    "        def func(w1, w2):\n",
    "            return sum(l1 == l2 for l1, l2 in zip(w1, w2))\n",
    "        while True:\n",
    "            shuffle(words)\n",
    "            g = master.guess(words[0])\n",
    "            if   g == 6: return\n",
    "            elif g == 0: words = [w for w in words[1:] if func(w, words[0]) == 0]\n",
    "            else       : words = [w for w in words[1:] if func(w, words[0]) >= g]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        copy_num = self.nums.copy()\n",
    "        for i in range(len(copy_num)):\n",
    "            import random\n",
    "            index = random.randint(0, len(copy_num)-1)\n",
    "            copy_num[i], copy_num[index] = copy_num[index], copy_num[i]\n",
    "        return copy_num\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        res = list(self.nums)\n",
    "        n = len(res)\n",
    "        i = 0\n",
    "        while i < n:\n",
    "            j = random.randint(i, n - 1)\n",
    "            if j != i:\n",
    "                res[i], res[j] = res[j], res[i]\n",
    "            i += 1\n",
    "        return res\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = [i for i in nums]\n",
    "        self.initial = [i for i in nums]       \n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = list(self.initial)\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffled = [0] * len(self.nums)\n",
    "        m = len(self.nums)\n",
    "        for i in range(m):\n",
    "            j = random.randrange(len(self.nums))\n",
    "            shuffled[i] = self.nums.pop(j)\n",
    "        self.nums = shuffled\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums[::]\n",
    "        self.start = nums.copy()\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.start.copy()\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        import random\n",
    "        n = len(self.nums)\n",
    "        for i in range(n-1):\n",
    "            j = random.randint(i,n-1)\n",
    "            self.nums[i], self.nums[j] = self.nums[j], self.nums[i]\n",
    "        return self.nums\n",
    "        \n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.org_list = nums.copy()\n",
    "        self.l1 = nums.copy()\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.l1 = self.org_list.copy()\n",
    "        return self.l1\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        cl1 = []\n",
    "        l = len(self.l1)\n",
    "        for i in range(len(self.l1)):\n",
    "            n1 = random.randint(0,l-1-i)\n",
    "            self.l1[n1],self.l1[-1]=self.l1[-1],self.l1[n1]\n",
    "            cl1.append(self.l1.pop())\n",
    "        self.l1 = cl1.copy()\n",
    "        return self.l1\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.list = nums\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.list\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        copy_list = self.list[:]\n",
    "        random.shuffle(copy_list)\n",
    "        return copy_list\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums=nums\n",
    "        self.origin=nums[:]\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.origin\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        n=len(self.nums)\n",
    "        tmp=self.nums\n",
    "        for l in range(n):\n",
    "            r=random.randint(0,n-1)\n",
    "            tmp[r],tmp[l]=tmp[l],tmp[r]\n",
    "        return tmp\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.arr1 = nums\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.arr1\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffArr = self.arr1.copy()\n",
    "        random.shuffle(shuffArr)\n",
    "        return shuffArr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.list = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.list\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        cloned_list = self.list[:]\n",
    "        for i in range(len(cloned_list)):\n",
    "            temp = cloned_list[i]\n",
    "            idx = random.randint(i,len(cloned_list)-1)\n",
    "            cloned_list[i] = cloned_list[idx]\n",
    "            cloned_list[idx] = temp\n",
    "        return cloned_list\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        # 存储一份原数组的备份用以reset\n",
    "        self.original = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.original.copy()\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        # 初始化shuffle数组\n",
    "        shuffled = [0] * len(self.nums)\n",
    "        # 每次随机从原数组中取出一个放入shuffle数组\n",
    "        for i in range(len(self.nums)):\n",
    "            index = random.randint(0,len(self.nums)-1)\n",
    "            shuffled[i] = self.nums.pop(index)\n",
    "        self.nums = shuffled\n",
    "        return self.nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.ori = nums\n",
    "        self.bak = nums[:]\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.bak = self.ori[:]\n",
    "        return self.ori\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffled = [0] * len(self.ori)\n",
    "        for i in range(len(self.ori)):\n",
    "            random_num = random.randrange(len(self.bak))\n",
    "            shuffled[i] = self.bak.pop(random_num)\n",
    "        self.bak = shuffled\n",
    "        return self.bak\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\r\n",
    "class Solution:\r\n",
    "\r\n",
    "    def __init__(self, nums: List[int]):\r\n",
    "        self.nums = nums\r\n",
    "\r\n",
    "\r\n",
    "    def reset(self) -> List[int]:\r\n",
    "        return self.nums\r\n",
    "\r\n",
    "\r\n",
    "    def shuffle(self) -> List[int]:\r\n",
    "        tmp = self.nums.copy()\r\n",
    "        random.shuffle(tmp)\r\n",
    "        return tmp\r\n",
    "\r\n",
    "\r\n",
    "\r\n",
    "# Your Solution object will be instantiated and called as such:\r\n",
    "# obj = Solution(nums)\r\n",
    "# param_1 = obj.reset()\r\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        import random\n",
    "        nums_copy = self.nums\n",
    "        return random.sample(nums_copy, len(nums_copy))\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = [i for i in nums]\n",
    "        self.initial = [i for i in nums]       \n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = list(self.initial)\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffled = [0] * len(self.nums)\n",
    "        for i in range(len(self.nums)):\n",
    "            j = random.randrange(len(self.nums))\n",
    "            shuffled[i] = self.nums.pop(j)\n",
    "        self.nums = shuffled\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        a = self.nums[::]\n",
    "        random.shuffle(a)\n",
    "        return a\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.l = [n for n in nums]\n",
    "        self.length = len(nums)\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.l\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        s=list(range(self.length))\n",
    "        random.shuffle(s)\n",
    "        return [self.l[i] for i in s]\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "# 注意等概率\n",
    "    \n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.d = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.d\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        co = copy.deepcopy(self.d)\n",
    "        n = []\n",
    "        while len(co) > 0:\n",
    "            x = random.randint(0,len(co)-1)\n",
    "            n.append(co[x])\n",
    "            co.pop(x)\n",
    "        return n\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.original = nums\n",
    "        self.nums = nums[:]\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.original[:]\n",
    "        return self.original\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        random.shuffle(self.nums)\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.N = len(nums)\n",
    "        \n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        new_order = [i for i in range(self.N)]\n",
    "        random.shuffle(new_order)\n",
    "        return [self.nums[i] for i in new_order]\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.original = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.original.copy()\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        for i in range(len(self.nums)):\n",
    "            j = random.randint(i, len(self.nums)-1)\n",
    "            self.nums[i], self.nums[j] = self.nums[j], self.nums[i]\n",
    "        return self.nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from random import sample\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "    def shuffle(self) -> List[int]:\n",
    "        return sample(self.nums,len(self.nums))\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums[:]\n",
    "        self.shufflenums = nums[:]\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.shufflenums = self.nums[:]\n",
    "        return self.shufflenums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        random.shuffle(self.shufflenums)\n",
    "        return self.shufflenums\n",
    "        \n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.length = len(nums)\n",
    "        self.org = nums.copy()  # 要加.copy()\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.org.copy()\n",
    "        return self.nums\n",
    "        \n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffled = [0] * len(self.nums)\n",
    "        for i in range(len(self.nums)):\n",
    "            j = random.randrange(len(self.nums))\n",
    "            shuffled[i] = self.nums.pop(j)\n",
    "        self.nums = shuffled\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.original = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.original.copy()\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        for i in range(len(self.nums)):\n",
    "            j = random.randint(i, len(self.nums)-1)\n",
    "            self.nums[i], self.nums[j] = self.nums[j], self.nums[i]\n",
    "        return self.nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.raw = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.raw\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        nums = copy.copy(self.raw)\n",
    "        random.shuffle(nums)\n",
    "        return nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    import itertools\n",
    "    import random\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        \n",
    "        self.r=nums\n",
    "        \n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        \n",
    "        return self.r\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        rc=self.r[:]\n",
    "        random.shuffle(rc)\n",
    "        return rc\n",
    "        \n",
    "        \n",
    "  \n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.l = nums\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.l\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        self.tmp = list(self.l)\n",
    "        for i in range(len(self.l)):\n",
    "            idx = random.randint(i,len(self.l)-1)\n",
    "            self.tmp[i], self.tmp[idx] = self.tmp[idx],self.tmp[i]\n",
    "        return self.tmp\n",
    "        \n",
    "        \n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.copy = copy.deepcopy(nums)\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.copy\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        random.shuffle(self.nums)\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.original = nums[:]\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.original[:]\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffled = [0] * len(self.nums)\n",
    "        for i in range(len(self.nums)):\n",
    "            j = random.randrange(len(self.nums))\n",
    "            shuffled[i] = self.nums.pop(j)\n",
    "        self.nums = shuffled\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.original = deepcopy(nums)\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = deepcopy(self.original)\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        for i in range(len(self.nums)):\n",
    "            j = random.randrange(i,len(self.nums))\n",
    "            self.nums[i],self.nums[j]=self.nums[j],self.nums[i]\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        nums = self.nums[:]\n",
    "        for i in range(len(nums)):\n",
    "            # 随机下标\n",
    "            r_index = random.randint(0, len(nums) - 1 - i)\n",
    "            # 最后一个值交换到此下标\n",
    "            nums[len(nums) - 1 - i], nums[r_index] = nums[r_index], nums[len(nums) - 1 - i]\n",
    "        return nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.origin = nums[:]\n",
    "        self.n = len(nums)\n",
    "    def reset(self) -> List[int]:\n",
    "        \n",
    "        self.nums = self.origin[:]\n",
    "        return self.nums\n",
    "    def shuffle(self) -> List[int]:\n",
    "        def swap(i,j):\n",
    "            self.nums[i],self.nums[j] = self.nums[j],self.nums[i]\n",
    "        for i in range(self.n):\n",
    "            a = random.randint(i,self.n-1)\n",
    "            swap(i,a)\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        import random\n",
    "        shuffled_lst, nums = [], self.nums.copy()\n",
    "        \n",
    "        for _ in range(len(nums)):\n",
    "            tmp = random.choice(nums)\n",
    "            shuffled_lst.append(tmp)\n",
    "            nums.remove(tmp)\n",
    "        del nums\n",
    "        return shuffled_lst\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        self.shuffle_nums = self.nums.copy()\n",
    "        for i in range(len(self.shuffle_nums)):\n",
    "            swap_index = random.randrange(i, len(self.shuffle_nums))\n",
    "            self.shuffle_nums[i], self.shuffle_nums[swap_index] = self.shuffle_nums[swap_index], self.shuffle_nums[i]\n",
    "        return self.shuffle_nums\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        nums1 = self.nums.copy()\n",
    "        random.shuffle(nums1)\n",
    "        return nums1\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        # 存储一份原数组的备份用以reset\n",
    "        self.original = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.original.copy()\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        # 初始化shuffle数组\n",
    "        shuffled = [0] * len(self.nums)\n",
    "        # 每次随机从原数组中取出一个放入shuffle数组\n",
    "        for i in range(len(self.nums)):\n",
    "            index = random.randint(0,len(self.nums)-1)\n",
    "            shuffled[i] = self.nums.pop(index)\n",
    "        self.nums = shuffled\n",
    "        return self.nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from random import randint\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.ori = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.ori\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        ans = self.ori[:]\n",
    "        n = len(ans)\n",
    "        for i in range(n):   \n",
    "            j = randint(i, n - 1)\n",
    "            ans[i], ans[j] = ans[j], ans[i]\n",
    "        return ans  \n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        res = self.nums.copy()\n",
    "        import random\n",
    "        # random.shuffle(res)\n",
    "\n",
    "        # j = len(res) - 1\n",
    "        # while j > 0:\n",
    "        #     i = random.randint(0, j)\n",
    "        #     res[i], res[j] = res[j], res[i]\n",
    "        #     j -= 1\n",
    "\n",
    "        for i in range(len(res)):\n",
    "            j = random.randrange(i, len(res))\n",
    "            res[i], res[j] = res[j], res[i]\n",
    "        return res\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        copy_list = self.nums[:]\n",
    "        random.shuffle(copy_list)\n",
    "        return copy_list\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        # 存储一份原数组的备份用以reset\n",
    "        self.original = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.original.copy()\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        # 初始化shuffle数组\n",
    "        shuffled = [0] * len(self.nums)\n",
    "        # 每次随机从原数组中取出一个放入shuffle数组\n",
    "        for i in range(len(self.nums)):\n",
    "            index = random.randint(0,len(self.nums)-1)\n",
    "            shuffled[i] = self.nums.pop(index)\n",
    "        self.nums = shuffled\n",
    "        return self.nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums[:]\n",
    "        self.cur = self.nums[:]\n",
    "        self.l = len(self.nums)\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.cur = self.nums[:]\n",
    "        return self.cur\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        for i in range(self.l):\n",
    "            ti = random.randint(i, self.l - 1)\n",
    "            self.cur[i], self.cur[ti] = self.cur[ti], self.cur[i]\n",
    "        return self.cur\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.rand = random.Random()\n",
    "\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        copy = self.nums.copy()\n",
    "        n = len(self.nums)\n",
    "        for i in range(n):\n",
    "            r = i + self.rand.randint(0, n-i-1)\n",
    "            copy[i], copy[r] = copy[r], copy[i]\n",
    "\n",
    "        return copy\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self, nums):  #构造函数\n",
    "        self.nums = nums  #将传入的数组赋值给类的成员变量self.nums\n",
    "\n",
    "    def reset(self):\n",
    "        return self.nums  #返回存储在self.nums中的原始数组\n",
    "\n",
    "    def shuffle(self):\n",
    "        temp = list(self.nums) #将原始数组self.nums的内容复制到临时数组temp中\n",
    "        n = len(temp)\n",
    "        for i in range(n - 1, 0, -1):  #从最后一个元素到第一个元素的循环\n",
    "            # 随机选择一个位置\n",
    "            j = random.randint(0, i)\n",
    "            # 交换当前位置元素和随机选择的位置元素\n",
    "            temp[i], temp[j] = temp[j], temp[i]\n",
    "        return temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.origin = nums.copy()\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.origin.copy()\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        n = len(self.origin)\n",
    "        shuffled = [0] * n\n",
    "        for i in range(n):\n",
    "            index = random.randrange(len(self.nums))\n",
    "            shuffled[i] = self.nums.pop(index)\n",
    "        self.nums = shuffled\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "'''\n",
    "    # 调用api\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.ori = nums.copy()\n",
    "        self.input = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.ori\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        random.shuffle(self.input)\n",
    "        return self.input\n",
    "'''\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        import random\n",
    "        # rand_idxs = random.randint(0, len(self.nums))\n",
    "        rlist = list(self.nums)\n",
    "        for i in range(len(self.nums)):\n",
    "            rand_idx = random.randint(i, len(self.nums)-1)\n",
    "            rlist[i], rlist[rand_idx] = rlist[rand_idx], rlist[i]\n",
    "        # rand_idxs = random.sample(list(range(len(self.nums))), len(self.nums))\n",
    "        # rlist = []\n",
    "        # for i in range(len(self.nums)):\n",
    "        #     rlist.append(self.nums[rand_idxs[i]])\n",
    "        return rlist\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        self.temp = list(self.nums)\n",
    "        for i in range(len(self.nums)):\n",
    "            idx = random.randint(i, len(self.nums) - 1)\n",
    "            self.temp[i], self.temp[idx] = self.temp[idx], self.temp[i]\n",
    "        return self.temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.original = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.original.copy()\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffled = [0] * len(self.nums)\n",
    "        for i in range(len(self.nums)):\n",
    "            j = random.randrange(len(self.nums))\n",
    "            shuffled[i] = self.nums.pop(j)\n",
    "        self.nums = shuffled\n",
    "        return self.nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.init = list(nums)\n",
    "        self.nums = nums\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums[:] = self.init\n",
    "        self.init = list(self.init)\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        for i in range(len(self.nums)):\n",
    "            j = randrange(i, len(self.nums))\n",
    "            self.nums[i], self.nums[j] = self.nums[j], self.nums[i]\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums=nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        n=self.nums[:]\n",
    "        result=[]\n",
    "        for i in range(len(n),0,-1):\n",
    "            _index=random.randint(0,i-1)\n",
    "            result.append(n.pop(_index))\n",
    "        return result\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums=nums\n",
    "        self.res=nums.copy()\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        n=len(self.res)\n",
    "        for i in range(n):\n",
    "            j=random.randrange(i,n)\n",
    "            self.res[i],self.res[j]=self.res[j],self.res[i]\n",
    "        return self.res\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.resetNums = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.resetNums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffleNums = []\n",
    "        while len(self.nums) > 0:\n",
    "            j = randrange(0, len(self.nums))\n",
    "            shuffleNums.append(self.nums.pop(j))\n",
    "        self.nums = shuffleNums\n",
    "        return shuffleNums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.nums0 = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.nums0.copy()\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        n = len(self.nums)\n",
    "        for i in range(n):\n",
    "            idx = random.randint(i, n - 1)\n",
    "            self.nums[i], self.nums[idx] = self.nums[idx], self.nums[i]\n",
    "\n",
    "        return self.nums\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums=nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        newlist=self.nums.copy()\n",
    "        for i in range(len(newlist)-1):\n",
    "            a=random.randint(i,len(newlist)-1)\n",
    "            if a==i:\n",
    "                continue\n",
    "            t=newlist[i]\n",
    "            newlist[i]=newlist[a]\n",
    "            newlist[a]=t\n",
    "        return newlist\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.init = list(nums)\n",
    "        self.nums = nums\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.init\n",
    "        self.init = list(self.init)\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffle(self.nums)\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        return sorted(self.nums, key=lambda x: random.random())\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.ori = nums[:]\n",
    "        self.nums = nums[:]\n",
    "        self.n = len(nums)\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.ori[:]\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        new_num = []\n",
    "        for _ in range(self.n):\n",
    "            j = random.randrange(len(self.nums))\n",
    "            new_num.append(self.nums[j])\n",
    "            self.nums = self.nums[:j] + self.nums[j+1:]\n",
    "        self.nums = new_num[:]\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.frozen = nums\n",
    "        self.nums = nums[:]\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.frozen[:]\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffled = [0] * len(self.nums)\n",
    "        for i in range(len(self.nums)):\n",
    "            j = random.randrange(len(self.nums))\n",
    "            shuffled[i] = self.nums.pop(j)\n",
    "        self.nums = shuffled\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.origin = self.nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.origin.copy()\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffle = self.nums.copy()\n",
    "        res = []\n",
    "        for _ in range(len(self.nums)):\n",
    "            r = random.randrange(len(shuffle))\n",
    "            a = shuffle.pop(r)\n",
    "            res.append(a)\n",
    "        return res\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.org = nums.copy()\n",
    "        self.list = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.org\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        random.shuffle(self.list)\n",
    "        return self.list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.origin = nums.copy()\n",
    "        self.nums = nums\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.origin\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        for i in range(len(self.nums)):\n",
    "            j = random.randrange(i,len(self.nums))\n",
    "            self.nums[i],self.nums[j] = self.nums[j],self.nums[i]\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.init = list(nums)\n",
    "        self.nums = nums\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums[:] = self.init\n",
    "        self.init = list(self.init)\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffle(self.nums)\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.original = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.original.copy()\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffled = [0] * len(self.nums)\n",
    "        hashmap = {i: self.nums[i] for i in range(len(self.nums))}\n",
    "        for i in range(len(self.nums)):\n",
    "            idx = random.choice(list(hashmap.keys()))\n",
    "            shuffled[i] = hashmap[idx] \n",
    "            del hashmap[idx]\n",
    "                        \n",
    "        self.nums = shuffled\n",
    "        return self.nums\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\n",
    "import copy\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        self.temp = self.nums[:]\n",
    "        random.shuffle(self.temp)\n",
    "\n",
    "        return self.temp\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.original = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.original\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        import random\n",
    "        nums = self.nums\n",
    "\n",
    "        for i in range(len(nums)):\n",
    "            idx = random.randint(i, len(nums)-1)\n",
    "            nums[i], nums[idx] = nums[idx], nums[i]\n",
    "\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.origin = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.origin.copy()\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        n = len(self.nums)\n",
    "        for i in range(n):\n",
    "            idx = random.randrange(i, n)\n",
    "            print(idx)\n",
    "            self.nums[i], self.nums[idx] = self.nums[idx], self.nums[i]\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffle_nums = self.nums.copy()\n",
    "        random.shuffle(shuffle_nums)\n",
    "        return shuffle_nums\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "import random\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.ori = nums[:]\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.ori\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        nums = self.ori[:]\n",
    "\n",
    "        for i in range(len(nums)):\n",
    "            temp = random.randint(i, len(nums)-1)\n",
    "            nums[temp], nums[i] = nums[i], nums[temp]\n",
    "        return nums\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.array = nums\n",
    "        self.copy = copy.copy(self.array)\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.copy = copy.copy(self.array)\n",
    "        return self.copy\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        random.shuffle(self.copy)\n",
    "        return self.copy\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.temp =list(nums)\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        \n",
    "        for i in range(len(self.nums)):\n",
    "            idx = random.randint(i, len(self.nums) - 1)\n",
    "            self.temp[i], self.temp[idx] = self.temp[idx], self.temp[i]\n",
    "        return self.temp\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    \n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        res = self.nums.copy()\n",
    "        n = len(self.nums)\n",
    "        for i in range(n):\n",
    "            idx = i + randint(0, n - i - 1)\n",
    "            res[i], res[idx] = res[idx], res[i]\n",
    "        return res\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.original = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.original\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        for i in range(len(self.nums)):\n",
    "            j = randrange(i, len(self.nums))\n",
    "            self.nums[i], self.nums[j] = self.nums[j], self.nums[i]\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.New = nums\n",
    "        self.Old = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.New = self.Old.copy()\n",
    "        return self.New\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        # print(*self.New)\n",
    "        random.shuffle(self.New)\n",
    "        # print(*self.New)\n",
    "        return self.New\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.ori = nums[:]\n",
    "        self.nums = nums[:]\n",
    "        self.n = len(nums)\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.ori[:]\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        new_num = []\n",
    "        for _ in range(self.n):\n",
    "            j = random.randrange(len(self.nums))\n",
    "            new_num.append(self.nums[j])\n",
    "            self.nums = self.nums[:j] + self.nums[j+1:]\n",
    "        self.nums = new_num[:]\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.original = nums.copy()\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.original.copy()\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffled = [0] * len(self.nums)\n",
    "        for i in range(len(self.nums)):\n",
    "            j = random.randrange(len(self.nums))\n",
    "            shuffled[i] = self.nums.pop(j)\n",
    "        self.nums = shuffled\n",
    "        return self.nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        self.temp = list(self.nums)\n",
    "        for i in range(len(self.nums)):\n",
    "            idx = random.randint(i, len(self.nums) - 1)\n",
    "            self.temp[i], self.temp[idx] = self.temp[idx], self.temp[i]\n",
    "        return self.temp\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "        self.original = nums.copy()\n",
    "\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        self.nums = self.original.copy()\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        for i in range(len(self.nums)):\n",
    "            j = random.randrange(i, len(self.nums))\n",
    "            self.nums[i], self.nums[j] = self.nums[j], self.nums[i]\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\n",
    "import copy\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        self.temp = copy.copy(self.nums)\n",
    "        random.shuffle(self.temp)\n",
    "\n",
    "        return self.temp\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.nums\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        shuffle_num = self.nums.copy()\n",
    "        for i in range(len(shuffle_num)):\n",
    "            swap_index = random.randint(i, len(shuffle_num) - 1)\n",
    "            shuffle_num[i], shuffle_num[swap_index] = shuffle_num[swap_index], shuffle_num[i]\n",
    "        return shuffle_num\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.list = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        \"\"\"\n",
    "        Resets the array to its original configuration and return it.\n",
    "        \"\"\"\n",
    "        return self.list\n",
    "\n",
    "\n",
    "    def shuffle(self) -> List[int]:\n",
    "        \"\"\"\n",
    "        Returns a random shuffling of the array.\n",
    "        \"\"\"\n",
    "        copy_list = self.list[:]\n",
    "        random.shuffle(copy_list)\n",
    "        return copy_list\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\n",
    "class Solution:\n",
    "    def __init__(self, nums: List[int]):\n",
    "        self.default = nums[:]\n",
    "        self.nums = nums\n",
    "\n",
    "    def reset(self) -> List[int]:\n",
    "        return self.default\n",
    "        \n",
    "    def shuffle(self) -> List[int]:\n",
    "        n = len(self.nums)\n",
    "        for i in range(n):\n",
    "            rand = random.randint(i,n-1)\n",
    "            self.nums[rand], self.nums[i] = self.nums[i], self.nums[rand]\n",
    "        return self.nums\n",
    "\n",
    "\n",
    "\n",
    "# Your Solution object will be instantiated and called as such:\n",
    "# obj = Solution(nums)\n",
    "# param_1 = obj.reset()\n",
    "# param_2 = obj.shuffle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        result = []\n",
    "        for i in range(len(nums) // 2):\n",
    "            result.append(nums[i])\n",
    "            result.append(nums[i + (len(nums) // 2)])\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        new=[0]*2*n\n",
    "        for i in range(0,n):\n",
    "            new[2*i]=nums[i]\n",
    "            new[2*i+1]=nums[n+i]\n",
    "        return new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans = [0] * (2 * n)\n",
    "        for i in range(n):\n",
    "            ans[2 * i] = nums[i]\n",
    "            ans[2 * i + 1] = nums[n + i]\n",
    "        return ans\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        new_nums=[]\n",
    "        for i in range(n):\n",
    "            new_nums.append(nums[i])\n",
    "            new_nums.append(nums[i+n])\n",
    "        return(new_nums)    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        result = [0] * (len(nums))\n",
    "        count = 0\n",
    "        for i in nums[0:n]:\n",
    "            result[count] = i\n",
    "            count += 2\n",
    "        count = 1\n",
    "        for i in nums[n:]:\n",
    "            result[count] = i\n",
    "            count += 2\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(n):\n",
    "            ans.append(nums[i])\n",
    "            ans.append(nums[n+i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        num=[]\n",
    "        num1=nums[0:n]\n",
    "        num2=nums[n:n*2]\n",
    "        for x in range(n):\n",
    "            num.append(num1[x])\n",
    "            num.append(num2[x])\n",
    "        return num\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(n):\n",
    "            res.append(nums[i])\n",
    "            res.append(nums[i + n])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        nums_1=nums[:]\n",
    "        for a in range(0,2*n):\n",
    "            if a<n:\n",
    "                nums[2*a]=nums_1[a]\n",
    "            else:\n",
    "                b=a-n\n",
    "                c=2*b+1\n",
    "                c=int(c)\n",
    "                nums[c]=nums_1[a]\n",
    "        return nums\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        nums[::2], nums[1::2]= nums[:n], nums[n:]\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        a=list()\n",
    "        n=len(nums)//2\n",
    "        for i in range(0,n):\n",
    "            a.append(nums[i])\n",
    "            a.append(nums[n+i])\n",
    "       \n",
    "        return a\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans =  [0] * len(nums)\n",
    "        ans[::2], ans[1::2] = nums[:n], nums[n:]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans = [0]*(2*n)\n",
    "        for i in range(n):\n",
    "            ans[2*i]=nums[i]\n",
    "            ans[2*i+1]=nums[i+n]\n",
    "        return ans\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        out = []\n",
    "        for i in range(n):\n",
    "            out.append(nums[i])\n",
    "            out.append(nums[i+n])\n",
    "        return out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self,nums: List[int], n: int) -> List[int]: \n",
    "        a=[]\n",
    "        for i in  range(n):\n",
    "            a.append(nums[i])\n",
    "            a.append(nums[i+n])\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        lst = []\n",
    "        lst.extend(nums)\n",
    "        k = 0\n",
    "        for i in range(0,2*n-1,2):\n",
    "            nums[i]=lst[k]\n",
    "            k += 1\n",
    "        for i in range(1,2*n,2):\n",
    "            nums[i] = lst[k]\n",
    "            k+=1\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        a = nums[:n]\n",
    "        b = nums[n:]\n",
    "\n",
    "        alla = []\n",
    "\n",
    "        z = zip(a,b)\n",
    "        for i,j in z:\n",
    "            alla.append(i)\n",
    "            alla.append(j)\n",
    "        # for i in range (0,n):\n",
    "        #     alla.append(a[i])\n",
    "        #     alla.append(b[i])\n",
    "        return alla"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        nums[::2], nums[1::2] = nums[:n], nums[n:]\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        nums[::2],nums[1::2] = nums[:n],nums[n:]\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        res1 = nums[:n]\n",
    "        res2 = nums[n:]\n",
    "        res = []\n",
    "        for i in range(n):\n",
    "            res.append(res1[i])\n",
    "            res.append(res2[i])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans = []\n",
    "        i = 0\n",
    "        for i in range(n): \n",
    "            ans.append(nums[i])\n",
    "            ans.append(nums[i+n])\n",
    "\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        x=[]\n",
    "        for i in range(0,n):\n",
    "            x=x+nums[i:i+1]+nums[i+n:i+n+1]\n",
    "        return x\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        def get_desired_index(j):\n",
    "            if j < n:\n",
    "                return 2*j\n",
    "            else:\n",
    "                return 2*(j-n)+1\n",
    "        for i in range(2*n):\n",
    "            j = i\n",
    "            while nums[i] > 0:\n",
    "                j = get_desired_index(j)\n",
    "                nums[i], nums[j] = nums[j], -nums[i]\n",
    "\n",
    "        for i in range(2*n):\n",
    "            nums[i] = -nums[i]\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        result=[0]*(2*n)\n",
    "        for i in range(n):\n",
    "            result[i*2]=nums[i]\n",
    "            result[i*2+1]=nums[i+n]\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        n=len(nums)//2\n",
    "        ans=[]\n",
    "        for i in range(n):\n",
    "            ans.append(nums[i])\n",
    "            ans.append(nums[n+i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans = [0] * (2 * n)\n",
    "        for i in range(n):\n",
    "            ans[2 * i] = nums[i]\n",
    "            ans[2 * i + 1] = nums[n + i]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        a = []\n",
    "        a.extend(nums)\n",
    "        k = 0\n",
    "        for i in range (0,2*n-1,2):\n",
    "            nums [i] = a[k]\n",
    "            k+=1\n",
    "        for i in range (1,2*n-1,2):\n",
    "            nums[i] = a[k]\n",
    "            k+=1\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\tdef shuffle(self,nums,n):\n",
    "\t\tnums[::2],nums[1::2]=nums[:n],nums[n:]\n",
    "\t\treturn nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans=[0]*2*n\n",
    "        \n",
    "        for i in range(n):\n",
    "            ans[2*i]=nums[i]\n",
    "            ans[2*i+1]=nums[n+i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(n):\n",
    "            res.append(nums[i])\n",
    "            res.append(nums[n + i])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        nums[::2], nums[1::2] = nums[:n], nums[n:]\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        newnums=[]\n",
    "        for i in range(n):\n",
    "            newnums.append(nums[i])\n",
    "            newnums.append(nums[n+i])\n",
    "        return newnums\n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        tmp = []\n",
    "        for i in range(0,n):\n",
    "            j = n + i\n",
    "            tmp.extend([nums[i],nums[j]])\n",
    "        return tmp\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans = [0] * (2 * n)\n",
    "        for i in range(n):\n",
    "            ans[2 * i] = nums[i]\n",
    "            ans[2 * i + 1] = nums[n + i]\n",
    "        return ans\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        return sum (zip(nums[:n], nums[n:]),())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        new = [0] * (2 * n)\n",
    "        for i in range(n):\n",
    "            new[2 * i] = nums[i]\n",
    "            new[2 * i + 1] = nums[i + n]\n",
    "        return new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        nums[::2], nums[1::2] = nums[:len(nums) // 2], nums[len(nums) // 2:]\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        z=[]\n",
    "        for i in range(n):\n",
    "            z.append(nums[i])\n",
    "            z.append(nums[i+n])\n",
    "        return z"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        r = []\n",
    "        for i in range(n):\n",
    "            r.append(nums[i])\n",
    "            r.append(nums[i+n])\n",
    "        return r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        n1=nums[:n]\n",
    "        n2=nums[n:]\n",
    "        result=[]\n",
    "        for i in range(len(n1)):\n",
    "            result.append(n1[i])\n",
    "            result.append(n2[i])\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        lst3=[]\n",
    "        lst1=nums[0:n]\n",
    "        lst2=nums[n:2*n]\n",
    "        for pair in zip(lst1,lst2):\n",
    "            lst3.extend(pair)\n",
    "        return lst3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        left = nums[:n]\n",
    "        right = nums[n:]\n",
    "        result = []\n",
    "        for i in range(n):\n",
    "            result.append(left[i])\n",
    "            result.append(right[i])\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        # 思路：新建一个数组，逐步加入数据\n",
    "        # new = []\n",
    "        # for i in range(n):\n",
    "        #     new.append(nums[i])\n",
    "        #     new.append(nums[n+i])\n",
    "        # return new\n",
    "        ans = [0] * (2 * n)\n",
    "        for i in range(n):\n",
    "            ans[2 * i] = nums[i]\n",
    "            ans[2 * i + 1] = nums[n + i]\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "\n",
    "        # mem: O(n)\n",
    "        \"\"\"\n",
    "        result = []\n",
    "        for i in range(n):\n",
    "            result.append(nums[i])\n",
    "            result.append(nums[i + n])\n",
    "        return result\n",
    "        \"\"\"\n",
    "\n",
    "        # mem: O(1)\n",
    "        \"\"\"\n",
    "        1. 題目有提到 nums[i] 最大是 1000 \n",
    "           每個元素能夠儲存的位元數大多是 32bits\n",
    "\n",
    "        2. 把 nums[i] 原本的數值往左移動 10 bits\n",
    "           再把 nums[i + n] 做 bitwise OR 加到 nums[i]\n",
    "           意思就是 nums[i] 存兩個數值 (bit manipulation)\n",
    "        \n",
    "        3. 從 nums[n - 1] 把數值抽出來\n",
    "           從最後面開始填回去\n",
    "        \"\"\"\n",
    "\n",
    "        for i in range(n):\n",
    "            nums[i] = nums[i] << 10\n",
    "            nums[i] = nums[i] | nums[i + n]\n",
    "\n",
    "        j = 2*n - 1\n",
    "        for i in range(n - 1, -1, -1):\n",
    "            # 從 xn, yn 的 nums 開始抽出來\n",
    "            y = nums[i] & (2**10 - 1) # 取 1023 (全部都是 1)\n",
    "            x = nums[i] >> 10\n",
    "            nums[j]     = y\n",
    "            nums[j - 1] = x\n",
    "            j -= 2\n",
    "        return nums\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        return [(nums[i//2] if i%2==0 else nums[len(nums)//2+i//2] ) for i in range(len(nums))]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        nums1 = nums[:n]\n",
    "        nums2 = nums[n:len(nums)]\n",
    "        new = []\n",
    "        for i in range(n):\n",
    "            new.append(nums1[i])\n",
    "            new.append(nums2[i])\n",
    "        return new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans = [0]*(2*n)\n",
    "        for i in range(n):\n",
    "            ans[2*i]=nums[i]\n",
    "            ans[2*i+1]=nums[i+n]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        list=[]\n",
    "        for i in range(n):\n",
    "            list.append(nums[i])\n",
    "            list.append(nums[i+n])\n",
    "        return list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        res =[]\n",
    "        for i in range(n):\n",
    "            res.append(nums[i])\n",
    "            res.append(nums[i+n])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        n = int(len(nums)/2)\n",
    "        l = []\n",
    "        for i in range(n):\n",
    "            l.extend([nums[i], nums[i+n]])\n",
    "        return l\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        nums2 =[]\n",
    "        for i in range(n):\n",
    "            nums2.append(nums[i])\n",
    "            nums2.append(nums[i+n])\n",
    "        return nums2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        xlist = []\n",
    "        ylist = []\n",
    "        for i in range(n):\n",
    "            xlist.append(nums[i])\n",
    "        for j in range(n, n*2):\n",
    "            ylist.append(nums[j])\n",
    "        res = []\n",
    "        for i in range(n):\n",
    "            res.append(xlist[i])\n",
    "            res.append(ylist[i])\n",
    "        return res\n",
    "        \n",
    "\n",
    "       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        res=[]\n",
    "        for i in range(n):\n",
    "            res.append(nums[i])\n",
    "            res.append(nums[n+i])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        x=nums[0:n]\n",
    "        y=nums[n:2*n]\n",
    "        ans=[]\n",
    "        for i in range(0,n):\n",
    "            ans.append(x[i])\n",
    "            ans.append(y[i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        res = [0]*2*n  # 创建1个长度为2n的数值res\n",
    "        res[::2] = nums[:n] # res偶数下标取num前半部分\n",
    "        res[1::2] = nums[n:] # res奇数下标取num后半部分\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        nums[::2], nums[1::2] = nums[:n], nums[n:]\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        lst3=[]\n",
    "        lst1=nums[0:n]\n",
    "        lst2=nums[n:2*n]\n",
    "        for pair in zip(lst1,lst2):\n",
    "            lst3.extend(pair)\n",
    "        return lst3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        nums[::2],nums[1::2]=nums[:n],nums[n:]\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        list_q,list_h,list_=nums[:n],nums[n:],[]\n",
    "        for i in range(n):\n",
    "            list_.append(list_q[i])\n",
    "            list_.append(list_h[i])\n",
    "        return list_\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        res = []\n",
    "        i, j = 0, n\n",
    "        while i < n:\n",
    "            res.append(nums[i])\n",
    "            res.append(nums[j])\n",
    "            i+=1\n",
    "            j+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "      result=[]\n",
    "      for i in range(2*n):\n",
    "        if((i+n)>2*n-1):\n",
    "          break\n",
    "        result.append(nums[i])\n",
    "        result.append(nums[i+n])\n",
    "      return result\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        nums[::2],nums[1::2]=nums[:n],nums[n:]\n",
    "        return nums\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans = [0] * (2 * n)\n",
    "        for i in range(n):\n",
    "            ans[2 * i] = nums[i]\n",
    "            ans[2 * i + 1] = nums[n + i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        length = len(nums)\n",
    "        result = [0] * length\n",
    "        ind = 0\n",
    "        for i in range(0, length // 2):\n",
    "            result[ind] = nums[i]\n",
    "            result[ind + 1] = nums[i + length // 2]\n",
    "            ind += 2\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        res = [0] * (2 * n)\n",
    "        for i in range(n):\n",
    "            res[2 * i] = nums[i]\n",
    "            res[2 * i +1] = nums[n + i]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(n):\n",
    "            res.append(nums[i])\n",
    "            res.append(nums[n+i])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\r\n",
    "        ans = []\r\n",
    "        for i in range(n):\r\n",
    "            ans.append(nums[i])\r\n",
    "            ans.append(nums[i+n])\r\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans=[]\n",
    "        for x,y in zip(nums[:n],nums[n:]):\n",
    "            ans.append(x)\n",
    "            ans.append(y)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        ans = []\n",
    "        left = 0\n",
    "        right = len(nums)//2\n",
    "        while right < len(nums):\n",
    "            ans.append(nums[left])\n",
    "            ans.append(nums[right])\n",
    "            left += 1\n",
    "            right += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def shuffle(self, nums: List[int], n: int) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(n):\n",
    "            res.append(nums[i])\n",
    "            res.append(nums[n+i])\n",
    "        return res\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
